home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue74 / misc / tougher / ClientSocket.cpp.txt next >
Encoding:
Text File  |  2002-08-14  |  790 b   |  43 lines

  1. // Implementation of the ClientSocket class
  2.  
  3. #include "ClientSocket.h"
  4. #include "SocketException.h"
  5.  
  6.  
  7. ClientSocket::ClientSocket ( std::string host, int port )
  8. {
  9.   if ( ! Socket::create() )
  10.     {
  11.       throw SocketException ( "Could not create client socket." );
  12.     }
  13.  
  14.   if ( ! Socket::connect ( host, port ) )
  15.     {
  16.       throw SocketException ( "Could not bind to port." );
  17.     }
  18.  
  19. }
  20.  
  21.  
  22. const ClientSocket& ClientSocket::operator << ( const std::string& s ) const
  23. {
  24.   if ( ! Socket::send ( s ) )
  25.     {
  26.       throw SocketException ( "Could not write to socket." );
  27.     }
  28.  
  29.   return *this;
  30.  
  31. }
  32.  
  33.  
  34. const ClientSocket& ClientSocket::operator >> ( std::string& s ) const
  35. {
  36.   if ( ! Socket::recv ( s ) )
  37.     {
  38.       throw SocketException ( "Could not read from socket." );
  39.     }
  40.  
  41.   return *this;
  42. }
  43.